package com.yan.linkedmapdemo;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeMap;

/**
 * @author taoge
 * @Date 2024/8/2 11:42
 * @Description
 */
public class Demo2 {
    public static void main(String[] args) {
        TreeMap<Student , Integer> map = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                if(o1.getAge() > o2.getAge()){
                    return 1;
                }else if(o1.getAge() < o2.getAge()){
                    return -1;
                }else{
                    return 0;
                }
            }
        });
        map.put(new Student("a" , 1) , 1);
        map.put(new Student("e" , 5) , 5);
        map.put(new Student("d" , 4) , 4);
        map.put(new Student("c" , 3) , 3);
        map.put(new Student("b" , 2) , 2);
        Set<Student> students = map.keySet();
        students.forEach(item-> System.out.println(item + "--" + map.get(item)));
    }
}
